package org.sca.middle.cmpe.client;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.History;

/**
 * <p>Updated 3/6/2014: replaced deprecated class com.google.gwt.user.client.Element with com.google.gwt.dom.client.Element</p>
 * @author rikscarborough
 * @author Kevin Carlen
 */
public class DisplayUtils {

	public static enum Displays {

		SignupForm,
		ListBox,
		FighterForm,
		ReportGen,
		ReportView
	}

	public static void changeDisplay(Displays display, boolean history) {
		if (history) {
			History.newItem("display:" + display.toString());
		}
		changeDisplay(display);
	}

	public static void changeDisplay(Displays display) {
		for (Displays d : Displays.values()) {
			if (!d.equals(display)) {
				Element element = Document.get().getElementById(d.toString());
				if (element != null) {
					element.getStyle().setDisplay(Style.Display.NONE);
				}
			} else {
				Element element = Document.get().getElementById(display.toString());
				if (element != null) {
					element.getStyle().setDisplay(Style.Display.BLOCK);
				}
			}
		}
	}

	public static void resetDisplay() {
		Document.get().getElementById("SearchBar").getStyle().setDisplay(Style.Display.BLOCK);
		changeDisplay(Displays.SignupForm);
	}

	public static void clearDisplay() {
		Document.get().getElementById("SearchBar").getStyle().setDisplay(Style.Display.NONE);
		for (Displays d : Displays.values()) {
			Element element = Document.get().getElementById(d.toString());
			if (element != null) {
				element.getStyle().setDisplay(Style.Display.NONE);
			}
		}
		if(Document.get().getElementById(Displays.ReportGen.toString()) != null) {
			Document.get().getElementById(Displays.ReportGen.toString()).removeFromParent();
		}
		if(Document.get().getElementById(Displays.ReportView.toString()) != null) {
			Document.get().getElementById(Displays.ReportView.toString()).removeFromParent();
		}

	}
}
